package Server.ExtComponents.socket;


import Server.ExtComponents.BaseConfig.MServerConfig;
import org.jboss.netty.channel.*;
import org.jboss.netty.handler.execution.ExecutionHandler;


public class MServerFrameChannelPipelineFactory  implements ChannelPipelineFactory {



    private final ChannelHandler idleStateHandler;//change final

    private final ExecutionHandler executionHandler;

    public MServerFrameChannelPipelineFactory(ChannelHandler idleStateHandler,ExecutionHandler executionHandler){
        this.idleStateHandler=idleStateHandler;
        this.executionHandler=executionHandler;
    }


    @Override
    public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline= Channels.pipeline(this.idleStateHandler);
        /**解码器*****/
        pipeline.addLast("decoder", new MServerFrameDecoder(MServerConfig.maxFrameLength
                ,MServerConfig.lengthFieldOffset,MServerConfig.lengthFieldLength
                ,MServerConfig.lengthAdjustment,MServerConfig.initialBytesToStrip));
        /**链路超时检查**/
        pipeline.addLast("idleStateCheckHandler",new MServerFrameIdleStateCheckHandler());
        /**handler 处理将会调用executor执行业务逻辑处理*/
        pipeline.addLast("handler",new MServerFrameHandler());//ChannelUpstreamHandler or ChannelDownstreamHandler类型
        pipeline.addLast("executor", this.executionHandler);//return worker Thread
        pipeline.addLast("encoder", new MServerFrameEncoder());
        return pipeline;
    }


}
